<Query Kind="Program">
  <DisableMyExtensions>true</DisableMyExtensions>
</Query>

void Main()
{
	var timeZones = new List<TimeZone>();

	var xml = XDocument.Load(@"C:\dev\FlipIt other\windowsZones.xml");
	var version = xml.Descendants("mapTimezones").Attributes("typeVersion").First().Value;
		
	var mapZoneElements = from c in xml.Root.Descendants("mapZone")
						  select c;
	
	foreach (var e in mapZoneElements)
	{
		var timeZoneID = e.Attribute("other").Value;
			
		var timeZone = timeZones.SingleOrDefault(t => t.TimeZoneID == timeZoneID);
		if (timeZone == null)
		{
			timeZone = new TimeZone {TimeZoneID = timeZoneID };
			timeZones.Add(timeZone);
		}
		
		var typeAttribute = e.Attribute("type").Value;
		var potentialNames = typeAttribute.Split(" ");
		foreach (var potentialName in potentialNames)
		{
			var name = CleanName(potentialName);
			if (!timeZone.Cities.Contains(name))
			{
				timeZone.Cities.Add(name);
			}
		}
	}

	Console.WriteLine($"; Generated by GenerateFlipItTimeZoneCities.linq using https://github.com/unicode-org/cldr/blob/master/common/supplemental/windowsZones.xml version {version}");
	foreach (var timeZone in timeZones)
	{
		Console.WriteLine($"{timeZone.TimeZoneID}={String.Join(',', timeZone.Cities)}");
	}
}

string CleanName(string s)
{
	var i = s.LastIndexOf('/');
	if (i == -1)
		return s;
	return s.Substring(i+1).Replace('_', ' ');
}

class TimeZone
{
	public string TimeZoneID { get; set; }
	public List<string> Cities { get; } = new List<string>();
}

// You can define other methods, fields, classes and namespaces here
